package com.ruoyi.factorydata.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.factorydata.domain.CraftProcessRelation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.factorydata.domain.CraftProcessMaterialRelation;
import com.ruoyi.factorydata.service.ICraftProcessMaterialRelationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工艺工序物料Controller
 * 
 * @author ruoyi
 * @date 2025-07-15
 */
@RestController
@RequestMapping("/craftprocessmaterial/craftprocessmaterial")
public class CraftProcessMaterialRelationController extends BaseController
{
    @Autowired
    private ICraftProcessMaterialRelationService craftProcessMaterialRelationService;

    /**
     * 查询工艺工序物料列表
     */
    @PreAuthorize("@ss.hasPermi('craftprocessmaterial:craftprocessmaterial:list')")
    @GetMapping("/list")
    public TableDataInfo list(CraftProcessMaterialRelation craftProcessMaterialRelation)
    {
        startPage();
        List<CraftProcessMaterialRelation> list = craftProcessMaterialRelationService.selectCraftProcessMaterialRelationList(craftProcessMaterialRelation);
        return getDataTable(list);
    }

    /**
     * 导出工艺工序物料列表
     */
    @PreAuthorize("@ss.hasPermi('craftprocessmaterial:craftprocessmaterial:export')")
    @Log(title = "工艺工序物料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CraftProcessMaterialRelation craftProcessMaterialRelation)
    {
        List<CraftProcessMaterialRelation> list = craftProcessMaterialRelationService.selectCraftProcessMaterialRelationList(craftProcessMaterialRelation);
        ExcelUtil<CraftProcessMaterialRelation> util = new ExcelUtil<CraftProcessMaterialRelation>(CraftProcessMaterialRelation.class);
        util.exportExcel(response, list, "工艺工序物料数据");
    }

    /**
     * 获取工艺工序物料详细信息
     */
    @PreAuthorize("@ss.hasPermi('craftprocessmaterial:craftprocessmaterial:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(craftProcessMaterialRelationService.selectCraftProcessMaterialRelationById(id));
    }

    /**
     * 新增工艺工序物料
     */
    @PreAuthorize("@ss.hasPermi('craftprocessmaterial:craftprocessmaterial:add')")
    @Log(title = "工艺工序物料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CraftProcessMaterialRelation craftProcessMaterialRelation)
    {
        return toAjax(craftProcessMaterialRelationService.insertCraftProcessMaterialRelation(craftProcessMaterialRelation));
    }

    /**
     * 修改工艺工序物料
     */
    @PreAuthorize("@ss.hasPermi('craftprocessmaterial:craftprocessmaterial:edit')")
    @Log(title = "工艺工序物料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CraftProcessMaterialRelation craftProcessMaterialRelation)
    {
        return toAjax(craftProcessMaterialRelationService.updateCraftProcessMaterialRelation(craftProcessMaterialRelation));
    }

    /**
     * 删除工艺工序物料
     */
    @PreAuthorize("@ss.hasPermi('craftprocessmaterial:craftprocessmaterial:remove')")
    @Log(title = "工艺工序物料", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(craftProcessMaterialRelationService.deleteCraftProcessMaterialRelationByIds(ids));
    }
}
